// https://leetcode.cn/problems/valid-triangle-number/description/

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int r = nums.size() - 1;
        int ret = 0;
        for(int i = r; i >= 2; i--) {
            int l = 0, r = i - 1;
            while(l < r) 
            {
                if(nums[l] + nums[r] > nums[i]) 
                {
                    ret += r - l;
                    r--;
                }else 
                {
                    l++;
                }
            }
        }
        return ret;
    }
};